package com.java.comprehensive.arithmetic.leecode.tags.array;

/**
 * @program: comprehensive-service
 * @description: 盛最多水的容器
 * @author: 窦绍飞
 * @create: 2021-12-07 17:57
 **/
public class LeetCode_11 {

	public static int maxArea(int[] height) {
		int result = 0;

		for (int i = 0; i < height.length - 1; i++) {
			int leftTemp = height[i];
			for (int j = i + 1; j < height.length; j++) {
				int tempX = Math.min(leftTemp, height[j]);
				result = Math.max((j - i) * tempX, result);
			}
		}

		return result;
	}

	public static int maxAreaOne(int[] height) {
		int maxarea = 0, l = 0, r = height.length - 1;
		while (l < r) {
			maxarea = Math.max(maxarea, Math.min(height[l], height[r]) * (r - l));
			if (height[l] < height[r])
				l++;
			else
				r--;
		}
		return maxarea;
	}

	//时间超出限制
	public static int maxAreaTwo(int[] height) {
		int length = height.length - 1;
		//创建两个变量 一个是最左侧标识 一个是最右侧标识
		int i = 0, j = i + 1;
		// 存储最大的数
		int result = Integer.MIN_VALUE;
		while (i <= length) {
			while (j <= length) {
				//能存水的高度
				int altitude = Math.min(height[i], height[j]);
				//能存水的长度
				int len = j - i;
				result = Math.max(result, altitude * len);
				j++;
			}
			i++;
			j = i + 1;
		}

		return result;
	}

	//时间超出限制
	public static int maxAreaThree(int[] height) {
		//创建两个变量 一个是最左侧标识 一个是最右侧标识
		int i = 0, j = height.length - 1;
		// 存储最大的数
		int result = Integer.MIN_VALUE;

		while (i < j) {
			int i1 = height[i];
			int i2 = height[j];
			int size = j - i;
			if (i1 >= i2) {
				result = Math.max(result, i2 * size);
				j--;
			} else {
				result = Math.max(result, i1 * size);
				i++;
			}
		}

		return result;
	}

	public static void main(String[] args) {
		int[] nums = {1, 8, 6, 2, 5, 4, 8, 3, 7};
		int i = maxAreaThree(nums);
		System.out.println(i);
	}
}
